//
//  HRZHomeGoodsPageViewController.m
//  EMarket
//
//  Created by 石头 on 2018/5/15.
//  Copyright © 2018年 好日子. All rights reserved.
//

#import "HRZHomeGoodsPageViewController.h"

// Controllers
#import "HRZGoodsDetailViewController.h"

// Models


// Views
#import "HRZShowGoodsSimpleInfoCell.h"
#import "HRZ_BrandsSortHeaderView.h"

// Vendors

// Categories
#import <UIImageView+WebCache.h>

// Others


static NSString * const HRZBrandsSortHeadViewID = @"HRZ_BrandsSortHeaderView";
static NSString * const HRZShowGoodsSimpleInfoCellID = @"HRZShowGoodsSimpleInfoCell";

@interface HRZHomeGoodsPageViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView *goodsCollctionView;

@end

@implementation HRZHomeGoodsPageViewController

#pragma mark - LazyLoad
- (UICollectionView *)goodsCollctionView {
    
    if (!_goodsCollctionView) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.minimumLineSpacing = 5;
        layout.minimumInteritemSpacing = 3;
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _goodsCollctionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _goodsCollctionView.delegate = self;
        _goodsCollctionView.dataSource = self;
        [self.view addSubview:_goodsCollctionView];
        
        _goodsCollctionView.frame = CGRectMake(0, 0, kScreenWidth,kScreenHeight - HRZTopNavH - HRZBottomTabH - 40);
        _goodsCollctionView.showsVerticalScrollIndicator = NO;
        _goodsCollctionView.showsHorizontalScrollIndicator = NO;
        
        
        //  注册header
        [_goodsCollctionView registerNib:[UINib nibWithNibName:@"HRZ_BrandsSortHeaderView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HRZBrandsSortHeadViewID];
        //注册Cell
        [_goodsCollctionView registerNib:[UINib nibWithNibName:@"HRZShowGoodsSimpleInfoCell" bundle:nil] forCellWithReuseIdentifier:HRZShowGoodsSimpleInfoCellID];
    }
    
    return _goodsCollctionView;
}

#pragma mark - LifeCyle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do view setup here.
    
    [self setupUI];
    
    [self setupData];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Public

#pragma mark - Private
/** 设置UI */
- (void)setupUI {
    self.goodsCollctionView.backgroundColor = [UIColor whiteColor];
}

/** 获取数据 */
- (void)setupData {
    
}

#pragma mark - Getter

#pragma mark - Setter
- (void)setGoodsTypeItem:(HRZGoodsTypeItem *)goodsTypeItem {
    _goodsTypeItem = goodsTypeItem;
    [_goodsCollctionView reloadData];
}

#pragma mark - ------<UICollectionViewDataSource>------
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 0;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HRZShowGoodsSimpleInfoCell *gridCell = [collectionView dequeueReusableCellWithReuseIdentifier:HRZShowGoodsSimpleInfoCellID forIndexPath:indexPath];
//    gridCell.goodsItem = _goodsTypeItem.supplierArray[indexPath.section].goodsArray[indexPath.row];
    return  gridCell;
}

#pragma mark - ------<UICollectionViewDelegate>------
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(kScreenWidth, 40);
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    UICollectionReusableView *reusableView = nil;
    if (kind == UICollectionElementKindSectionHeader) {
        HRZ_BrandsSortHeaderView *brandsHeader = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HRZBrandsSortHeadViewID forIndexPath:indexPath];
        brandsHeader.testHeaderTitle = @"";
        reusableView = brandsHeader;
    }
    return reusableView;
}

#pragma mark - ItemSize
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake((kScreenWidth - 4)/2, (kScreenWidth - 4)/2 + 60);
}

#pragma mark - ------<didsected>------
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
        
        HRZGoodsDetailViewController *goodsDetailVC = [[HRZGoodsDetailViewController alloc] init];
//        goodsDetailVC.goodTitle = item.goods_name;
//        goodsDetailVC.goodPrice = item.goods_price;
//        goodsDetailVC.goodImageView = item.goods_url;
        
        [self.navigationController pushViewController:goodsDetailVC animated:YES];
}



@end
